package com.lmq.singleton;


import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

//enum since 1.5,本身也是一个class内
public enum EnumSingle {
    INSTANCE;
    public EnumSingle getInstance(){
        return INSTANCE;
    }


}

class Test{
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        EnumSingle instance1 = EnumSingle.INSTANCE;
        EnumSingle instance2 = EnumSingle.INSTANCE;
        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(String.class,int.class);
        declaredConstructor.setAccessible(true);
        EnumSingle instance3 = declaredConstructor.newInstance();



        System.out.println(instance1);
//       Exception in thread "main" java.lang.NoSuchMethodException: com.lmq.singleton.EnumSingle.<init>()
        System.out.println(instance3);
    }
}